﻿using System;
using System.Collections.Generic;

using CtpTrader.Logic.Entity;
using CtpTrader.Logic.Core.Common;

namespace CtpTrader.Logic.Core.Trade
{
    /// <summary>
    /// 持仓单位
    /// </summary>
    public class PositionUnit
    {
        /// <summary>
        /// 策略名称
        /// </summary>
        public string Strategy { get; set; }

        /// <summary>
        /// 账户
        /// </summary>
        public Account Account { get; set; }

        /// <summary>
        /// 证券
        /// </summary>
        public Instrument Instrument { get; set; }

        /// <summary>
        /// 交易级别单位
        /// </summary>
        public BarUnit BarUnit { get; set; }

        /// <summary>
        /// 仓位方向
        /// </summary>
        public DirectionType DirectionType { get; set; }

        /// <summary>
        /// 判断两个持仓基本字段类是否相等
        /// </summary>
        /// <param name="obj">持仓基本字段类</param>
        /// <returns>如果各个字段都相等则返回true，或者返回false</returns>
        public override bool Equals(object obj)
        {
            if (obj == null) return false;

            PositionUnit target = obj as PositionUnit;

            if (this.Strategy == target.Strategy &&
                this.Account.Number == target.Account.Number &&
                this.Instrument.InstrumentID == target.Instrument.InstrumentID &&
                this.BarUnit.Level == target.BarUnit.Level &&
                this.BarUnit.TimeSpan == target.BarUnit.TimeSpan &&
                this.DirectionType == target.DirectionType)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
